import { createSlice } from '@reduxjs/toolkit'

export const SettingSlice = createSlice({
    // 命名空间，在调用action的时候会默认的设置为action的前缀,保证唯一.不重名
    name: 'setting',
    initialState: {
        fontSize:'1rem',
        bg_1:'#3e9597',
        bg_2:'white',
        color_1:'white',
        color_2:'',
        color_3:'',
        alipayId:'0',
        wechatId:'1',
    },
    reducers: {
        // 定义的action-赋值的方式进行数据的改变
        fontSizeChange: (state, action) => {
            state.fontSize =action.payload 
        },
        bg_1Change: (state, action) => {
            state.bg_1 = action.payload
        },
        bg_2Change: (state, action) => {
            state.bg_2 = action.payload
        },
        color_1Change: (state, action) => {
            state.color_1 = action.payload
        },
        color_2Change: (state, action) => {
            state.color_2 = action.payload
        },
        color_3Change: (state, action) => {
            state.color_3 = action.payload
        },
        alipayIdChange: (state, action) => {
            state.alipayId = action.payload
        },
        wechatIdChange: (state, action) => {
            state.wechatId = action.payload
        },
    },
})

// 导出action
export const { fontSizeChange, bg_1Change, bg_2Change, color_1Change, color_2Change, color_3Change, alipayIdChange, wechatIdChange } = SettingSlice.actions

// 异步数据处理
// export const incrementAsync = (amount) => (dispatch) => {
//     setTimeout(() => {
//         dispatch(incrementByAmount(amount))
//     }, 1000)
// }

// export const selectCount = (state) => state.counter.value

// 导出reducer
const SettingSliceReducer = SettingSlice.reducer
export default SettingSliceReducer